

<?php
/*****
1. 已经处理: 只取有库存的数据记录;
***/



require_once("../config/include.inc.php");
require_once("../class/Common_Function.php");

$site = $_GET['site'];




//==========feed 所有字段===============
$id = ""; //字母数字字符
$title = ""; //文本。不应超过70个字符。连续输入文本不要另启一行。
$description = ""; //文本 10,000 文字以下。连续输入不要另启一行。并且不要重复输入相同字符。
$feed_condition = "";
$price = ""; //数字 货币单位 （例:15.00 USD）
$availability = "";
$link = "";  //目标网页的网址（必须包含 http:// 部分）
$image_link = ""; //网址。（网址必须以“http://”或“https://”开头。）4MB以下；至少800像素（服饰商品至少250x250像素）
$gtin  = "";
$mpn  = ""; //字母数字字符 --- CJ+id
$brand = "";
$google_product_category = ""; 
$gender   = "";
$age_group  = "";
$size  = "";
$color  = "";
$material  = "";
$pattern = "";
$item_group_id = "";
$tax  = ""; 
$shipping  = "";
$shipping_weight  = "";
$sale_price = ""; //数字 货币单位 （例：15.00 USD）
$sale_price_effective_date = "";
$additional_image_link = ""; 
$product_type= ""; 

//设置CivilLaser默认值
if($site == "civillaser-jp" ||
	$site == "civillaser-usa" ||
	$site == "civillaser-uk" ||
	$site == "civillaser-au" ||
	$site == "civillaser-ca" ||
	$site == "civillaser-fr" ||
	$site == "civillaser-de" ||
	$site == "civillaser-ru"){
		$feed_condition = "New";
		$availability = "in stock";
		$brand = "CivilLaser";
		$google_product_category = "Electronics > Circuit Components > Optoelectronics > Laser Diodes"; 
		$gender   = "Unisex";
		$age_group  = "Adult";
		$product_type= "Industry & Business > Machinery > Laser Equipment Parts"; 
		//$shipping  = "::Express:0";// 在账户级设置
}



//==========feed 字段取值===============
$commonFunction = new Common_Function();
if($site == "civillaser-jp"){
	$localPrice = 1;
	$countryCode = "JP"; 


	//google feed上传解析有问题 多加些有值的字段
	//$adwords_labels = "Laser Module";
	//$adwords_redirect  = "www.jp.civillaser.com";

	//$brand = "CivilLaser";
	//$tax  = "JP::0: "; 
	//$shipping  = "JP:01:Express:0"; 
	//$google_product_category = "Electronics > Circuit Components > Optoelectronics > Laser Diodes"; 
	//$product_type= "Electronics > Circuit Components > Optoelectronics > Laser products"; 
	$sqlProductList = "select * from products p,products_description pd where p.products_id=pd.products_id and p.products_quantity>0 order by p.products_id desc";
	//$sqlProductList = "select * from products p,products_description pd where p.products_id=pd.products_id  and p.products_id=5 order  by p.products_id desc";
	$resultProductList = $db_CJ->Execute($sqlProductList);
	while (!$resultProductList->EOF) {
		$id = $resultProductList->fields['products_id'];	
		$title = $resultProductList->fields['products_name'];
		if(strlen($title)>70){
			//$title = substr($title,0,70);
			$title = $commonFunction->cut_str($title,70,0,'UTF-8');
		}
		$title = addslashes($title);
		$description = $resultProductList->fields['products_description'];
		if(strpos($description,"\n")){
			//遇到换行 只取换行前那部分
			$i = strpos($description,"\n");
			$description = substr($description,0,$i-1); 
		}
		$description = str_replace("<div>","",$description);
		$description = str_replace("</div>","",$description);
		$description = str_replace("<br />","",$description);
		$description = str_replace("<b>","",$description);
		$description = str_replace("</b>","",$description);
		if(strlen($description)>1000){
			//$description = substr($description,0,1000);
			$description = $commonFunction->cut_str($description,1000,0,'UTF-8');
		}
		$description = addslashes($description);
		$link = "http://jp.civillaser.com/-p-".$id.".html";
		$image_link = $resultProductList->fields['products_image'];
		$image_link = str_replace(" ","%20",$image_link);
		$image_link = "http://jp.civillaser.com/images/".$image_link;
		$price = floor ($resultProductList->fields['products_price'] )." Yen";
		if($resultProductList->fields['products_price'] > $resultProductList->fields['products_price_sorter']){
			$sale_price = floor ($resultProductList->fields['products_price_sorter'] )." Yen";
		}else{
			$sale_price = "";
		}
		$mpn = "CJ".$id;
		//insert
		/*
		$sql_insert_feed = "INSERT INTO google_feed   
		(id,title,description,google_product_category,product_type,link,image_link,additional_image_link,google_condition,availability,price,sale_price,sale_price_effective_date,brand,gtin,mpn,identifier_exists,gender,age_group,color,size,material,pattern,item_group_id,tax,shipping,shipping_weight,multipack,adult,online_only,excluded_destination,expiration_date,loyalty_points,adwords_grouping,adwords_labels,adwords_redirect) 
		   values 
		('$id','$title','$description','$google_product_category','$product_type','$link','$image_link','$additional_image_link','$google_condition','$availability','$price','$sale_price','$sale_price_effective_date','$brand','$gtin','$mpn','$identifier_exists','$gender','$age_group','$color','$size','$material','$pattern','$item_group_id','$tax','$shipping','$shipping_weight',$multipack,'$adult','$online_only','$excluded_destination','$expiration_date','$loyalty_points','$adwords_grouping','$adwords_labels','$adwords_redirect')";
		*/
		$sql_insert_feed = "INSERT INTO google_feed   
		(id,title,description,feed_condition,price,availability,link,image_link,gtin,mpn,brand,google_product_category,gender,age_group,size,color,material,pattern,item_group_id,tax,shipping,shipping_weight,sale_price,additional_image_link,product_type) 
		   values 
		('$id','$title','$description','$feed_condition','$price','$availability','$link','$image_link','$gtin','$mpn','$brand','$google_product_category','$gender','$age_group','$size','$color','$material','$pattern','$item_group_id','$tax','$shipping','$shipping_weight','$sale_price','$additional_image_link','$product_type')";		

		$db->Execute($sql_insert_feed);
		$resultProductList->MoveNext();	
	}
}else if($site == "civillaser-usa" ||
	$site == "civillaser-uk" ||
	$site == "civillaser-au" ||
	$site == "civillaser-ca" ||
	$site == "civillaser-fr" ||
	$site == "civillaser-de" ||
	$site == "civillaser-ru"){
	//echo "+++++++++++++++++++++++";

	if($site == "civillaser-usa"){
		$localPrice = 1;
	    $currency = "USD";
	}else if($site == "civillaser-uk"){
		$localPrice = 0.585;
	    $currency = "GBP";
	}else if($site == "civillaser-au"){
		$localPrice = 1.0679;
	    $currency = "AUD";
	}else if($site == "civillaser-ca"){
		$localPrice = 1.0746;
	    $currency = "CAD";
	}
	



	//*********Netherlands 荷兰*************
	//$localPrice = 1.5882;
	//$countryCode = "NLD";
	//$currency = "Hfl.";

	//*********Swizerland 瑞士*************
	//$localPrice = 0.9009;
	//$countryCode = "CHE";
	//$currency = "CHF";



	//google feed上传解析有问题 多加些有值的字段
	//$adwords_labels = "Laser Module";
	//$adwords_redirect  = "www.civillaser.com";


	//$brand = "CivilLaser";
	//$tax  = $countryCode."::0: "; 
	//$shipping  = $countryCode.":024:Express:0 ".$currency; 
	//$google_product_category = "Electronics > Circuit Components > Optoelectronics > Laser Diodes"; 
	//$product_type= "Electronics > Circuit Components > Optoelectronics > Laser products"; 
	$sqlProductList = "select * from products p,products_description pd where p.products_id=pd.products_id and p.products_quantity>0 order by p.products_id desc";
	//$sqlProductList = "select * from products p,products_description pd where p.products_id=pd.products_id and p.products_id =4 order by p.products_id desc"; //++++debug
	$resultProductList = $db_C->Execute($sqlProductList);
	while (!$resultProductList->EOF) {
		$id = $resultProductList->fields['products_id'];			
		$title = $resultProductList->fields['products_name'];
		if(strlen($title)>70){
			$title = substr($title,0,70);
		}
		$title = addslashes($title);
		$description = $resultProductList->fields['products_description'];
		if(strpos($description,"\n")){
			//遇到换行 只取换行前那部分
			$i = strpos($description,"\n");
			$description = substr($description,0,$i-1); 
		}
		$description = str_replace("<div>","",$description);
		$description = str_replace("</div>","",$description);
		$description = str_replace("<br />","",$description);
		$description = str_replace("<b>","",$description);
		$description = str_replace("</b>","",$description);
		if(strlen($description)>1000){
			$description = substr($description,0,1000);
		}		
		$description = addslashes($description);
		$link = "http://civillaser.com/-p-".$id.".html";
		$image_link = $resultProductList->fields['products_image'];
		$image_link = str_replace(" ","%20",$image_link);
		$image_link = "http://civillaser.com/images/".$image_link;
		$price = floor (floor ($resultProductList->fields['products_price'])*$localPrice)." ";
		if ($price == 0)$price = 1;
		$price = $price." ".$currency;
		if($resultProductList->fields['products_price'] > $resultProductList->fields['products_price_sorter']){
			$sale_price = floor (floor ($resultProductList->fields['products_price_sorter'])*$localPrice) ." ";
			$sale_price = $sale_price." ".$currency;
		}else{
			$sale_price = "";
		}	
		
		$mpn = "C".$id;
		//insert
		/**
		$sql_insert_feed = "INSERT INTO google_feed   
		(id,title,description,google_product_category,product_type,link,image_link,additional_image_link,google_condition,availability,price,sale_price,sale_price_effective_date,brand,gtin,mpn,identifier_exists,gender,age_group,color,size,material,pattern,item_group_id,tax,shipping,shipping_weight,multipack,adult,online_only,excluded_destination,expiration_date,loyalty_points,adwords_grouping,adwords_labels,adwords_redirect) 
		   values 
		('$id','$title','$description','$google_product_category','$product_type','$link','$image_link','$additional_image_link','$google_condition','$availability','$price','$sale_price','$sale_price_effective_date','$brand','$gtin','$mpn','$identifier_exists','$gender','$age_group','$color','$size','$material','$pattern','$item_group_id','$tax','$shipping','$shipping_weight',$multipack,'$adult','$online_only','$excluded_destination','$expiration_date','$loyalty_points','$adwords_grouping','$adwords_labels','$adwords_redirect')";		
		**/
		$sql_insert_feed = "INSERT INTO google_feed   
		(id,title,description,feed_condition,price,availability,link,image_link,gtin,mpn,brand,google_product_category,gender,age_group,size,color,material,pattern,item_group_id,tax,shipping,shipping_weight,sale_price,additional_image_link,product_type) 
		   values 
		('$id','$title','$description','$feed_condition','$price','$availability','$link','$image_link','$gtin','$mpn','$brand','$google_product_category','$gender','$age_group','$size','$color','$material','$pattern','$item_group_id','$tax','$shipping','$shipping_weight','$sale_price','$additional_image_link','$product_type')";		

		$db->Execute($sql_insert_feed);
		$resultProductList->MoveNext();	
	}
}else if($site == "l"){
	$brand = "LuckLaser";
	$tax  = $countryCode."::0: "; 
	$shipping  = $countryCode.":01:Express:0"; 
	$google_product_category = "Electronics > Circuit Components > Optoelectronics > Laser Diodes"; 
	$product_type= "Electronics > Circuit Components > Optoelectronics > Laser products"; 
	$sqlProductList = "select * from products p,products_description pd where p.products_id=pd.products_id order by p.products_id desc";
	//$sqlProductList = "select * from products p,products_description pd where p.products_id=pd.products_id and p.products_id=4 order by p.products_id desc";
	$resultProductList = $db_L->Execute($sqlProductList);
	while (!$resultProductList->EOF) {
		$id = $resultProductList->fields['products_id'];			
		$title = $resultProductList->fields['products_name'];
		if(strlen($title)>70){
			//$title = substr($title,0,70);
			$title = $commonFunction->cut_str($title,70,0,'UTF-8');
		}
		$title = addslashes($title);
		$description = $resultProductList->fields['products_description'];
		if(strpos($description,"\n")){
			//遇到换行 只取换行前那部分
			$i = strpos($description,"\n");
			$description = substr($description,0,$i-1); 
		}	
		$description = strip_tags($description);//去掉HTML及PHP标记
		$description = str_replace("<div>","",$description);
		$description = str_replace("</div>","",$description);
		$description = str_replace("<br />","",$description);
		$description = str_replace("<b>","",$description);
		$description = str_replace("</b>","",$description);		
		if(strlen($description)>1000){
			//$description = substr($description,0,1000);
			$description = $commonFunction->cut_str($description,1000,0,'UTF-8');
		}	
		$description = iconv('iso-8859-1','utf-8',$description);
		$description = addslashes($description);
		$link = "http://lucklaser.com/-p-".$id.".html";
		$image_link = $resultProductList->fields['products_image'];
		$image_link = str_replace(" ","%20",$image_link);
		$image_link = "http://lucklaser.com/images/".$image_link;
		$price = floor (floor ($resultProductList->fields['products_price'])*$localPrice)." ";
		if ($price == 0)$price = 1;
		if($resultProductList->fields['products_price'] > $resultProductList->fields['products_price_sorter']){
			$sale_price = floor (floor ($resultProductList->fields['products_price_sorter'])*$localPrice) ." ";
		}else{
			$sale_price = "";
		}		
		$mpn = "L".$id;
		//insert
		$sql_insert_feed = "INSERT INTO google_feed   
		(id,title,description,google_product_category,product_type,link,image_link,additional_image_link,google_condition,availability,price,sale_price,sale_price_effective_date,brand,gtin,mpn,identifier_exists,gender,age_group,color,size,material,pattern,item_group_id,tax,shipping,shipping_weight,multipack,adult,online_only,excluded_destination,expiration_date,loyalty_points,adwords_grouping,adwords_labels,adwords_redirect) 
		   values 
		('$id','$title','$description','$google_product_category','$product_type','$link','$image_link','$additional_image_link','$google_condition','$availability','$price','$sale_price','$sale_price_effective_date','$brand','$gtin','$mpn','$identifier_exists','$gender','$age_group','$color','$size','$material','$pattern','$item_group_id','$tax','$shipping','$shipping_weight',$multipack,'$adult','$online_only','$excluded_destination','$expiration_date','$loyalty_points','$adwords_grouping','$adwords_labels','$adwords_redirect')";		
		$db->Execute($sql_insert_feed);
		$resultProductList->MoveNext();	
	}
}else if($site == "ca"){
}




//get list data
$sqlFeedList = "select * from google_feed";
$resultFeedList = $db->Execute($sqlFeedList);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "订单列表"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>

<?php
//echo "+++++++++sql++++++++++".$sql_insert_feed;
?>

Complete !<br><br>


<a href="/googlefeed/index.php">Go back</a><br><br>

<div class="grayTable">	
<table >
<thead>
	<tr>
		<th scope="col" >ID</th>
	    <th scope="col" >Title</th>		
		<th scope="col" >Description</th>		
		<th scope="col" >Price</th>
	</tr>
</thead>

<tbody>	
<?php
while (!$resultFeedList->EOF) {
	$strTR = "<tr>";
	$strTR = $strTR."<td>".$resultFeedList->fields['id']."</td>";
	$strTR = $strTR."<td>".$resultFeedList->fields['title']."</td>";
	$strTR = $strTR."<td>".$resultFeedList->fields['description']."</td>";
	$strTR = $strTR."<td>".$resultFeedList->fields['price']."</td>";
	$strTR = $strTR."</tr>";
	echo $strTR;
	$resultFeedList->MoveNext();
}
?>

</tbody>
</table>

</div>

</body>
